package com.dinggou.shopjb.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dinggou.shopjb.R;
import com.dinggou.shopjb.bean.SignBean;

import java.util.List;

public class SignAdapter extends  CommonAdapter<SignBean>{
    public SignAdapter(Context context, List list) {
        super(context, list);
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_sign_info, parent, false);
            viewHolder = new ViewHolder(convertView);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.setData(position);
        return convertView;
    }

    class ViewHolder {
        private LinearLayout ll_bg;
        private LinearLayout ll_coupon;
        private ImageView iv_signed;
        private TextView tv_integral;
        private TextView tv_unit;
        private TextView tv_unit_bottom;
        private TextView tv_coupon;
        private TextView tv_time;

        public ViewHolder(View rootView) {
            rootView.setTag(ViewHolder.this);
            ll_bg = rootView.findViewById(R.id.ll_bg);
            ll_coupon = rootView.findViewById(R.id.ll_coupon);
            tv_integral = rootView.findViewById(R.id.tv_integral);
            tv_unit = rootView.findViewById(R.id.tv_unit);
            tv_unit_bottom = rootView.findViewById(R.id.tv_unit_bottom);
            tv_coupon = rootView.findViewById(R.id.tv_coupon);
            tv_time = rootView.findViewById(R.id.tv_time);
        }

        void setData(int position) {
            SignBean bean = mDatas.get(position);
            tv_integral.setText(bean.getGoods_num()+"");
            if (bean.isChecked()) {
                tv_integral.setTextColor(mContext.getResources().getColor(R.color.white));
                tv_unit_bottom.setTextColor(mContext.getResources().getColor(R.color.white));
                tv_unit.setTextColor(mContext.getResources().getColor(R.color.white));
                ll_bg.setBackgroundResource(R.drawable.shape_rect_round_20_blue);
                tv_time.setText("已签");
            } else {
                tv_integral.setTextColor(mContext.getResources().getColor(R.color.color_gray_03));
                tv_unit_bottom.setTextColor(mContext.getResources().getColor(R.color.color_gray_03));
                tv_unit.setTextColor(mContext.getResources().getColor(R.color.white));
                ll_bg.setBackgroundResource(R.drawable.shape_rect_round_all_20_gray);
                String time = position + 1 + "天";
                tv_time.setText(time);
            }
        }

    }
}
